<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/28
 * Time: 18:00
 */

namespace app\api\validate;


class IDCollection extends BaseValidate
{
    protected $rule = [
        'ids' => 'require|checkIDs'
    ];

    protected $message = [
        'ids' => 'ids必须是逗号分隔的多个正整数'
    ];

    protected function checkIDs($data)
    {
        $dataArray = explode(',', $data);

        if(empty($dataArray)){
            return false;
        }

        foreach ($dataArray as $id) {
            // 判断每个id是否是正整数
            if (!$this->isPositiveInteger($id)) {
                return false;
            }
        }

        return true;
    }
}